package com.zzyl.controller.web;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingPlanService;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 护理计划表 前端控制器
 * </p>
 *
 * @author 聂德祥
 * @since 2024-08-15
 */
@RestController
public class NursingPlanController extends BaseController {
    @Autowired
private NursingPlanService nursingPlanService;
    @GetMapping("/nursing/plan/search")
    public ResponseResult getNursingPlanAllPage(
            String name,
            Integer status,
            @RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingPlan> nursingProjectAll  = nursingPlanService.NursingPlanAllPage(name,status,pageNum,pageSize);
        return success(nursingProjectAll);
    }
    @PostMapping("/nursing/plan")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto ){
           nursingPlanService.addNursingPlan(nursingPlanDto);
           return success();
    }
    @GetMapping("/nursing/plan/{id}")
    public ResponseResult getNursingPlanById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getNursingPlanById(id);
        return success(nursingPlanVo);
    }
    @PutMapping("/nursing/plan/{id}")
    public ResponseResult updateNusingPlanById(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }
    @DeleteMapping("/nursing/plan/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
       nursingPlanService.deleteById(id);
       return success();
    }
    @PutMapping("/nursing/{id}/status/{status}")
    public ResponseResult enableOrDisable(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        NursingPlan nursingPlan = new NursingPlan();
        nursingPlan.setId(id);
        nursingPlan.setStatus(status);
        nursingPlanService.updateById(nursingPlan);
        return success();
    }
    @GetMapping("/nursing/plan")
    public ResponseResult getAll(){
        List<NursingPlan> list = nursingPlanService.list();
        return success(list);
    }
}
